﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Web.UI;
using QASPRibbon;
using QASPRibbon.Controls;
using System.Web.UI.WebControls.WebParts;

namespace QASPRibbonDemo.DemoTabs
{
    [ToolboxItemAttribute(false)]
    public class DemoTabs : WebPart
    {
        protected override void CreateChildControls()
        {
            #region Tab1

            var mru = _demoButtons();
            var tab1 = new RibbonTab("tab1", "QASPRibbon 14.3")
            {
                Sequence = 701,
                Groups = new[]
                {
                    #region Group 1
                    new RibbonGroup("group1", "Group 1")
                    {
                        Sections = new []
                        {
                            new RibbonGroupSection
                            {
                                Type = RibbonSectionType.OneRow,
                                DisplayMode = RibbonDisplayMode.Image32AndCaption,
                                Controls = new RibbonControl[]
                                {
                                    #region MRUSplitButton 1
                                    new RibbonMRUSplitButton("mru1", "MRUSplitButton 1")
                                    {
                                        InitialItem = mru.First().Id,
                                        Controls = new []
                                        {
                                            new RibbonMenuSection("section1", "Section 1")
                                            {
                                                DisplayMode = RibbonMenuDisplayMode.Menu,
                                                Controls = mru
                                            }
                                        }
                                    }
                                    #endregion
                                }
                                #endregion
                            },
                            RibbonGroupSection.Divider,
                            new RibbonGroupSection
                            {
                                Type = RibbonSectionType.TwoRows,
                                DisplayMode = RibbonDisplayMode.Image16AndCaption,
                                Controls = _demoButtons().Take(4)
                            },
                            RibbonGroupSection.Divider,
                            new RibbonGroupSection
                            {
                                Type = RibbonSectionType.ThreeRows,
                                DisplayMode = RibbonDisplayMode.Image16AndCaption,
                                Controls = _demoButtons().Take(3)
                            }
                        }
                    }
                }
            };

            RibbonManager.Current.AddTabToPage(tab1, Page, true);

            #endregion
        }

        private string[] _presidents = new[]
            {
                "Abraham Lincoln",
                "James Buchanan",
                "James Monroe",
                "James Polk",
                "John Quincy Adams",
                "Martin Van Buren"
            };

        private Random rnd = new Random();

        private IEnumerable<RibbonControl> _demoButtons()
        {
            return _presidents.Select(x => new RibbonButton(x.Replace(" ", string.Empty), x)
            {
                Image = RibbonImageDefinition.Standard(rnd.Next(0, 10), rnd.Next(0, 10)),
                OnClientClick = "alert('" + x + " has been clicked!');"
            }).Cast<RibbonControl>().ToArray();
        }
    }
}
